@extends('layouts.default')

@section('title')
	设备信息修改
@stop

@section('pre')
	<li class="active"><span>@yield('title')</span></li>
@stop

@section('css')
	<style type="text/css">
		.phone-group{
			height:30px;
		}
	</style>
@stop

@section('content')

<div class="row">
<div class="col-lg-12">
	
	<div class="main-box">
	<header class="main-box-header clearfix">
	<h2>设备信息查询</h2>
	</header>
	<div class="main-box-body clearfix">
	<form role="form">
	
	<div class="col-lg-4">
		<form role="form" action="{{ action('DeviceController@edit') }}" method="post">
			<div class="input-group">
				<div class="input-group-btn">
					<button type="button" id="edit-type" name="type" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">硬件序列号 <span class="caret"></span></button>
					<ul class="dropdown-menu">
						{{--<li><a href="#" id="id">设备ID</a></li>--}}
						<li><a href="#" id="hardware_serial">硬件序列号</a></li>
					</ul>
				</div>
				<input type="text" class="form-control" name="query" id="query" value="" placeholder="请输入查询信息">
				<input type="hidden" name="notic" id="query-notic" value="hardware_serial">
			</div>
			</div>
				<input type="submit" value='查询' name="submit" class="btn btn-success">
			</div>
		</form>
	</div>
</div>
</div>

@if( isset( $deviceData[0] ) )

<div class="row">
<div class="col-lg-12">
	
	<div class="main-box">
	<header class="main-box-header clearfix">
	<h2>查询结果</h2>
	</header>
	<div class="main-box-body clearfix">
	<form role="form" action="{{ action('DeviceController@edit') }}" method="post">
	
	<br/>
	
	<input id="dev-id" name="devId" type="hidden" value="{{ isset($devId)?$devId:'' }}">

	<div class="form-group col-lg-12">
		<label for="dev-title" class="col-lg-2 control-label">设备标题</label>
		<div class="col-lg-3">
			<input class="form-control" id="dev-title" name="title" type="text"  value="{{ $deviceData[0]->title }}">
		</div>
	</div>

	<div class="form-group col-lg-12">
		<label for="code1" class="col-lg-2 control-label">硬件序列号</label>
		<div class="col-lg-4">
			<input class="form-control" id="code1" type="text" value="{{ $deviceData[0]->hardware_serial }}" disabled="">
			<input type="hidden" name="hardware_serial" value="{{ $deviceData[0]->hardware_serial }}">
		</div>
	</div>

	<div class="form-group col-lg-12">
		<label for="code2" class="col-lg-2 control-label">通讯序列号</label>
		<div class="col-lg-4">
			<input class="form-control" id="code2" type="text" name="communication_serial" value="{{ $deviceData[0]->communication_serial }}" disabled="">
		</div>
	</div>
	
	@if( count($deviceData[0]->phones) > 0 )
		
		<?php $firstKey = array_keys($deviceData[0]->phones)[0];$k=0; ?>

		@foreach( $deviceData[0]->phones as $n => $phone )
			
			<?php $k++; ?>

			@if( $n == $firstKey )
				@if( isset($sphone) && $sphone == $phone )
				<div class="form-group col-lg-12 phone-group has-success" id="phone-number">
				@else
				<div class="form-group col-lg-12 phone-group" id="phone-number">
				@endif
					<input type="hidden" name="ids[]" value="{{ $n }}">
					<label for="phoneNum{{ $n+1 }}" class="col-lg-2 control-label">绑定手机号{{ $k }}</label>
					<div class="col-lg-2">
						<input class="form-control" id="phoneNum{{ $n+1 }}" type="text" name="phones[]" value="{{ $phone }}">
					</div>
					<div class="col-lg-3">
						<button type="button" class="md-trigger btn btn-primary mrg-b-lg"  id="add-phone" data-toggle="tooltip" data-placement="bottom" title="添加一个手机号">
							<span class="glyphicon glyphicon-plus"></span>
						</button>
					</div>
				</div>
			@else
				@if( isset($sphone) && $sphone == $phone )
				<div class="form-group col-lg-12 phone-group has-success" id="phone-numbe{{ $k }}">
				@else
				<div class="form-group col-lg-12 phone-group" id="phone-numbe{{ $k }}">
				@endif
					<input type="hidden" name="ids[]" value="{{ $n }}">
					<label for="phoneNum{{ $n+1 }}" class="col-lg-2 control-label">绑定手机号{{ $k }}</label>
					<div class="col-lg-2">
						<input class="form-control" id="phoneNum{{ $n+1 }}" name="phones[]" type="text"  value="{{ $phone }}">
					</div>
					<div class="col-lg-3">
						<button type="button" class="md-trigger btn btn-danger mrg-b-lg remove-phone" data-toggle="tooltip" data-placement="bottom" title="删除一个手机号">
							<span class="glyphicon glyphicon-minus"></span>
						</button>
					</div>
				</div>
			@endif

		@endforeach
	@endif
	@if(!$deviceData[0]->phones)
    <div class="form-group col-lg-12 phone-group" id="phone-number0">
        <input type="hidden" name="ids[]">
        <label for="phoneNum0" class="col-lg-2 control-label">绑定手机号</label>
        <div class="col-lg-2">
            <input class="form-control" id="phoneNum0" name="phones[n][0]" type="text"  value="">
        </div>
        <div class="col-lg-3">
        <button type="button" class="md-trigger btn btn-primary mrg-b-lg" id="add-phone" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="添加一个手机号">
            <span class="glyphicon glyphicon-plus"></span>
        </button>
        </div>
    </div>
    @endif


	<div class="form-group col-lg-12">
         <label for="" class="col-lg-2 control-label">设备地址</label>
         <div class="col-lg-10" >
            <div class="col-lg-1">
              <select id="loc_province" name="province" disabled></select>
            </div>
            <div class="col-lg-1 col-lg-offset-1"><select id="loc_city" name="city" disabled></select></div>
            <div class="col-lg-1 col-lg-offset-1"><select id="loc_town" name="town"></select></div>
            <div class="col-lg-3 col-lg-offset-1">
                <select id="group" name="group" class="form-control">
                @foreach($deviceData[0]->list as $k=>$v)
                <option value="{{$k}}">{{$v}}</option>
                @endforeach

                </select>
            </div>

         </div>
         <div class="col-lg-10 col-lg-offset-2" style="margin-top: 10px">

            <div class="col-lg-1">
                <input class="form-control" id="address1" name="address1" type="text" value="{{ isset($deviceData[0]->local[0])?$deviceData[0]->local[0]:'' }}">
            </div>
            <label for="address1" class="col-lg-1 control-label" style="text-align: left">栋</label>
            <div class="col-lg-1">
                <input class="form-control" id="address2" name="address2" type="text" value="{{ isset($deviceData[0]->local[1])?$deviceData[0]->local[1]:'' }}">
            </div>
            <label for="address2" class="col-lg-1 control-label" style="text-align: left">单元</label>
            <div class="col-lg-1">
                <input class="form-control" id="address3" name="address3" type="text" value="{{ isset($deviceData[0]->local[2])?$deviceData[0]->local[2]:'' }}">
            </div>
            <label for="address3" class="col-lg-1 control-label" style="text-align: left">室</label>

         </div>

	</div>



	<div class="form-group col-lg-12">
		<label for="dev-about" class="col-lg-2 control-label">设备简介</label>
		<div class="col-lg-8">
			<textarea class="form-control" id="dev-about" name="about" rows="3">{{ $deviceData[0]->about }}</textarea>
		</div>
	</div>
	

	
	<div class="col-lg-12" style="text-align: center;">
		<br/>
		<input type="submit" class="btn btn-primary" value="修改" name="edit">
	</div>
	
	
	</form>
	</div>
	</div>
</div>
</div>
@endif

@stop

@section('js')

<script type="text/javascript">
$(function(){
    $('#query-notic').val('hardware_serial');

    $('.dropdown-menu > li > a').on('click', function(){
        $('#edit-type').html($(this).text()+'<span class="caret"></span>');
        $('#query-notic').val($(this).attr('id'));

    });

    //添加手机号
    $('#add-phone').unbind('click').on('click', function(){

        var count = $('.phone-group').length;
        var phoneOrder;

        $('.phone-group:last').after(
            '<div class="form-group col-lg-12 phone-group" id="phone-number'+count+'"><label for="phoneNum'+count+'" class="col-lg-2 control-label">绑定手机号'+(count+1)+'</label><div class="col-lg-2"><input class="form-control" id="phoneNum'+count+'"name="phones[n]['+count+']" type="text" value=""></div><div class="col-lg-3"><button type="button" class="md-trigger btn btn-danger mrg-b-lg remove-phone" data-toggle="tooltip" data-placement="bottom" title="删除一个手机号"><span class="glyphicon glyphicon-minus"></span></button></div></div>'
        );

    });

    //删除手机号
    setInterval(function(){


        $(".remove-phone").unbind('click').on('click', function(){

            $(this).parent().parent().remove();

        });


    },500);
    //区域
    setTimeout(function(){
        $('#loc_province').val({{isset($deviceData[0])?$deviceData[0]->area[0]:0}}).trigger('change')
        var loc	= new Location()
        loc.fillOption('loc_city' , '0,'+$('#loc_province').val())
        loc.fillOption('loc_town' , '0,'+$('#loc_city').val())
        $('#loc_city').val({{isset($deviceData[0])?$deviceData[0]->area[1]:0}}).trigger('change')
        $('#loc_town').val({{isset($deviceData[0])?$deviceData[0]->area[2]:0}}).trigger('change')
        $('#group').val({{isset($deviceData[0])?$deviceData[0]->area[3]:0}})

    },10)
})





	</script>

@stop
